﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;

public partial class StreetCenter_AddAdmissibility : System.Web.UI.Page
{
    Admissibility admissibility = new Admissibility();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserStreet"] == null)
            WebHelper.AlertAndRedirect("登陆超时，请重新登陆","../Login.aspx");
        //Application["AdmissibilityLock"] = false;
        if (Request.QueryString["isquickadd"] == "1")
            btnadd_Click(new object(),new EventArgs());
    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        ClearText();
        if (!Convert.ToBoolean(Application["AdmissibilityLock"]))
        {
            Application["AdmissibilityLock"] = true;
            int noid = admissibility.GenerateNoid();
            ArrayList array = new ArrayList();
            array.Add(noid);
            array.Add(txbapplyname.Text);
            array.Add(txbaddress.Text);
            array.Add(txbreceivename.Text);
            if (string.IsNullOrEmpty(txbphone.Text))
                array.Add("");
            else
                array.Add(txbphone.Text);
            if (string.IsNullOrEmpty(txbdate.Text))
                array.Add(DateTime.Now);
            else
                array.Add(Convert.ToDateTime(txbdate.Text));
            ContentPlaceHolder cph = ((ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"));
            TextBox txb;
            for (int j = 1; j < 37; j++)
            {
                txb = (TextBox)cph.FindControl("TextBox" + j.ToString());
                array.Add(txb.Text);
            }
            array.Add("0");
            array.Add("0");
            array.Add(Session["UserStreet"].ToString());
            array.Add(DateTime.Now);
            array.Add(DateTime.Now);
            bool succ = admissibility.AddAdmissibility(array);
            Application["AdmissibilityLock"] = false;
            if (succ)
                //WebHelper.AlertAndCloseThenRefreshLastPage("添加成功！");
				Response.Redirect("../StreetCenter/AddApply.aspx?id="+noid.ToString());
            else
                WebHelper.Alert("出错！");
        }
        else
        {
            WebHelper.Alert("网络延时，请重新操作！");
            Application["AdmissibilityLock"] = false;
        }
    }
    protected void ClearText()
    {
        ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
        foreach (Control ctl in cph.Controls)
        {
            if (ctl.GetType().Name.Equals("TextBox"))
            {
                TextBox tb = new TextBox();
                tb = (TextBox)cph.FindControl(ctl.ID);
                if (string.IsNullOrEmpty(tb.Text))
                {
                    tb.Text = "";
                }
            }
        }
    }
}
